﻿namespace TestNewGuiFramework
{
    using Pps.Gui.Controls;

    internal class TemperatureWindow : BaseWindow
    {
        private static float indoorTemperatureValue = 22.0F;

        private Button temperatureHigh;
        private Button temperatureLow;

        private Label setLabel;
        private Label currentLabel;
        private Label title;
        private Label indoorSetTemperature;
        private Label indoorTemperature;

        public TemperatureWindow()
        {
            this.InitializeControls();
        }

        protected override void InitializeControls()
        {
            base.InitializeControls();

            this.title = new Label("Innentemperatur", 280, 50);
            this.title.TextAlignment = TextAlignment.Center;
            this.title.Size = new Pps.Gui.Base.Size(470, 50);

            this.currentLabel = new Label("Soll", 287, 120);
            this.currentLabel.Size = new Pps.Gui.Base.Size(200, 50);
            this.currentLabel.TextAlignment = TextAlignment.Center;

            this.setLabel = new Label("Ist", 530, 120);
            this.setLabel.Size = new Pps.Gui.Base.Size(200, 50);
            this.setLabel.TextAlignment = TextAlignment.Center;

            this.temperatureHigh = new Button("Wärmer", 287, 180, 200, 70);
            this.temperatureHigh.Clicked += TemperatureHigh;

            this.temperatureLow = new Button("Kälter", 287, 358, 200, 70);
            this.temperatureLow.Clicked += TemperatureLow;

            this.indoorSetTemperature = new Label(indoorTemperatureValue.ToString("F1") + " °C", 287, 285);
            this.indoorSetTemperature.Size = new Pps.Gui.Base.Size(200, 70);
            this.indoorSetTemperature.AutoSize = false;
            this.indoorSetTemperature.TextAlignment = TextAlignment.Center;

            this.indoorTemperature = new Label("22.0 °C", 530, 285);
            this.indoorTemperature.Size = new Pps.Gui.Base.Size(200, 70);
            this.indoorTemperature.AutoSize = false;
            this.indoorTemperature.TextAlignment = TextAlignment.Center;

            this.temperature.Selected = true;
            this.temperature.Enabled = true;

            this.AddControlsToWindow();
        }

        private void TemperatureLow()
        {
            indoorTemperatureValue -= 0.5F;
            this.indoorSetTemperature.Text = indoorTemperatureValue.ToString("F1") + " °C";
        }

        private void TemperatureHigh()
        {
            indoorTemperatureValue += 0.5F;
            this.indoorSetTemperature.Text = indoorTemperatureValue.ToString("F1") + " °C";
        }

        protected override void AddControlsToWindow()
        {
            base.AddControlsToWindow();

            this.AddChildControl(this.title);
            this.AddChildControl(this.currentLabel);
            this.AddChildControl(this.setLabel);
            this.AddChildControl(this.temperatureHigh);
            this.AddChildControl(this.temperatureLow);
            this.AddChildControl(this.indoorSetTemperature);
            this.AddChildControl(this.indoorTemperature);
        }

        protected override void Update()
        {
            System.Random test = new System.Random();

            this.indoorTemperature.Text = test.Next(100).ToString("F1") + " °C";
        }
    }
}